package main

import (
	"fmt"
	"sort"
)

type Student struct {
	name  string
	score int
}

// type StudentSlice []Student

// func (a StudentSlice) Len() int           { return len(a) }
// func (a StudentSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
// func (a StudentSlice) Less(i, j int) bool { return a[i].score < a[j].score }

func main() {
	s1 := Student{"tom", 90}
	s2 := Student{"ben", 60}
	s3 := Student{"sam", 70}
	Students := []Student{s1, s2, s3} //切片 Students := []Student{{"tom", 90}, {"ben", 60}, {"sam", 70}}
	fmt.Println(Students)
	// 按照分数从高到低排序
	// sort.Sort(data sort.Interface) // 实现 3 个方法的 Interface Ints
	// sort.Sort(StudentSlice(Students)) // 就地排序
	// fmt.Println(Students)
	// sort.Sort(sort.Reverse(StudentSlice(Students))) // 逆序排序

	sort.Slice(Students, func(i, j int) bool {
		// return Students[i].score > Students[j].score
		return Students[i].name < Students[j].name

	})
	fmt.Println(Students)

}
